<?php

namespace app\admin\controller;

use app\common\model\PracticeLog as PracticeLogModel;
use app\common\model\Member as MemberModel;
/**
 * 念佛禅坐记录控制器
 * Class Practicelog
 * @package app\admin\controller
 */
class Practicelog extends Base
{
    /**
     * [index  获取念珠记录]
     * @return json
     * @author [C。]
     */
    public function index()
    {
        $param = input('param.');
        $model = new PracticeLogModel;
        $mmodel = new MemberModel;
        $this->getPageAndSize($param);
        $map = [];
        $user = $this->user;
        try {
            $map['p.type'] = $param['type'];
            $count = $model->getCount($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getList($map, $this->from, $this->size,'pl.id,pl.memid,pl.starttime,pl.endtime,p.title,p.img');
            foreach($lists as &$v){
                $member = $mmodel->findData($v['memid'],'id','tel,username,img');
                $http = substr($member['img'],0,4);
                if($http != 'http'){
                    $v['userimg'] = config('domain_name').$member['img'];
                }else{
                    $v['userimg'] = $member['img'];
                }
                $v['tel'] = $member['tel'];
                $v['username'] = $member['username'];
            }
        } catch (\Exception $e) {
            return admin_json(-1, '获取失败' . $e->getMessage());
        }
        if($param['type'] == 1){
            $name = '念佛';
        }elseif($param['type'] == 2){
            $name = '禅坐';
        }
        writelog('查看'.$name.'记录列表',1,$user);
        return admin_json(1, '获取成功', [
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
}